package gov.nasa.anml.utility;


// mutable integers
// but using these as keys in a hashtable requires not changing the value
// i.e., be careful!
public class SimpleBoolean implements SimpleObject<SimpleBoolean> {

	public static final SimpleBoolean True = new SimpleBoolean(true);
	public static final SimpleBoolean False = new SimpleBoolean(false);
	
	public static SimpleBoolean make(boolean v) {
		return v ? True : False;
	}
	
	public boolean v;

	protected SimpleBoolean() {
		v = false;
	}

	protected SimpleBoolean(boolean v) {
		this.v = v;
	}

	public int hashCode() {
		return v ? 1231 : 1237;
	}
	
	public static final int hash(boolean b) {
		return b ? 1231 : 1237;
	}

	public boolean equals(Object obj) {
		if (obj instanceof SimpleBoolean
				&& v == ((SimpleBoolean) obj).v)
			return true;
		return false;
	}

	public boolean equals(SimpleBoolean obj) {
		if (v == obj.v)
			return true;
		return false;
	}

	public SimpleBoolean clone() {
		try {
			return (SimpleBoolean) super.clone();
		} catch (CloneNotSupportedException e) {
			// assert false;
		}
		return null;
	}

	public int compareTo(SimpleObject<SimpleBoolean> b) {
		SimpleBoolean o = (SimpleBoolean) b;
		if (this == null || o == null)
			return 1;
		boolean w = o.v;
		if (v) {
			if (!w)
				return 1;
		} else {
			if (w)
				return -1;
		}
		return 0;
	}

	public String toString() {
		return java.lang.Boolean.toString(v);
	}

	public void assign(SimpleBoolean c) {
		v = c.v;
	}
	
	public void assign(boolean v) {
		this.v = v;
	}

	public SimpleBoolean value() {
		return this;
	}
}
